package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;

import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import cn.lanqiao.entity.Score;


public class TeacherUpdateSourceFrm extends JDialog {
	
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel;
	private JTextField textid;
	private JTextField textsoure;
	private JTextField textnum;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			TeacherUpdateSourceFrm dialog = new TeacherUpdateSourceFrm();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 public TeacherUpdateSourceFrm(Score updateUser) {
	 this();
     this.textid.setText(updateUser.getSid());
     this.textnum.setText(updateUser.getScourse());
     this.textsoure.setText(updateUser.getSgrade());

 }
 
 public TeacherUpdateSourceFrm(Score updateUser,JTable table) {
	 this();
     this.textid.setText(updateUser.getSid());
     this.textnum.setText(updateUser.getScourse());
     this.textsoure.setText(updateUser.getSgrade());
     this.table=table;
     
 }
 
	/**
	 * Create the dialog.
	 */
	public TeacherUpdateSourceFrm() {
		setTitle("修改联系人");
		setBounds(100, 100, 529, 385);
		this.setLocationRelativeTo(null);
		getContentPane().setLayout(new BorderLayout());
		
		contentPanel = new JPanel();
		
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("学生学号");
		lblNewLabel.setBounds(36, 53, 72, 18);
		contentPanel.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("课程编号");
		lblNewLabel_1.setBounds(36, 129, 72, 18);
		contentPanel.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("学生成绩");
		lblNewLabel_2.setBounds(36, 214, 72, 18);
		contentPanel.add(lblNewLabel_2);
		
		JButton btnNewButton_3 = new JButton("保存修改");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//创建一个新文本框;
				String sid=textid.getText();
				String scourse=textnum.getText();
				String sgrade=textsoure.getText();
			
				//封装一个对象
				Score score=new Score(sid,scourse,sgrade);
				//调业务层
				cn.lanqiao.service.ScoreService service=new cn.lanqiao.service.impl.ScoreServiceImpl();
				service.updateUser(sid, score);
				//刷新
				
				TeacherUpdateSourceFrm.this.dispose();
				
				Object[][] datas = service.getAllScore();
			    String[] strs = new String[] {"学号", "课程编号", "\u6210\u7EE9"};
			    table.setModel(new DefaultTableModel(datas,strs));
			}
		});
		btnNewButton_3.setBounds(109, 262, 136, 53);
		contentPanel.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("取消");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//关闭
				TeacherUpdateSourceFrm.this.dispose();
				
			}
		});
		btnNewButton_4.setBounds(311, 262, 113, 53);
		contentPanel.add(btnNewButton_4);
		
		textid = new JTextField();
		textid.setBounds(257, 50, 146, 38);
		textid.setEnabled(false);
		contentPanel.add(textid);
		textid.setColumns(10);
		
		textsoure = new JTextField();
		textsoure.setBounds(257, 204, 146, 38);
		contentPanel.add(textsoure);
		textsoure.setColumns(10);
		
		textnum = new JTextField();
		textnum.setEnabled(false);
		textnum.setBounds(257, 129, 146, 36);
		contentPanel.add(textnum);
		textnum.setColumns(10);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
		}
	}
}
